<link rel="stylesheet" type="text/css" href="style.css" />
<?php
 
 
 
 class Pesanan{

/ function con_Pesanan($id_member){
	$kon = koneksi_db();
	$sql = "insert into pesanan values (NULL,'$id_member',now(),'T','T')";
	$query = mysql_query($sql,$kon);
  }
  
  function con_Pesanan_item($id_pesanan,$id,$harga){
	$kon2 = koneksi_db();
	$sql2 = "insert into pesanan_item values('$id_pesanan','$id',1,'$harga',0.0)";
	$query2 = mysql_query($sql2,$kon2);
  }
  
  function up_Pesanan($id_member,$id_pesanan){
	$kon = koneksi_db();
	$sql = "update pesanan set waktu = now() where Id_pesanan = '$id_pesanan and id_member = '$id_member'";
	$q   = mysql_query($sql);
  }
  
  
  # fungsi untuk melihat pesanan item, lalu melakukan update pada jumlah stok produk
  function view_pesanan_item($id_pesanan){
	$sql = "select * from pesanan_item where id_pesanan = '$id_pesanan'";
	$kon = koneksi_db();
	$q = mysql_query($sql,$kon);
	
	while ($f = mysql_fetch_array($q)){
		$sql3 = "update produk set stok = stok - '$f[qty]' where id_produk = '$f[id_produk]'";
		$q2 = mysql_query($sql3,$kon);
	}
  }
    # fungsi untuk mendapatkan jumlah item produk yang ada dikeranjang member
  function get_jml_item(){
	
	$id_member = $_SESSION['id_member'];
	$kon = koneksi_db();
	$sql = "select * from pesanan_item, pesanan where 
		   pesanan_item.id_pesanan = pesanan.id_pesanan and
		   pesanan.id_member = '$id_member' and
		   pesanan.dichekout = 'T'
		   ";
	$q = mysql_query($sql,$kon);
	$n = mysql_num_rows($q);
	
	return $n;
  }
  
  # fungsi untuk mengetahui total bayar dari keranjang member
  function get_tot_bayar(){
	$id_member = $_SESSION['id_member'];
	$kon = koneksi_db();
	$sql = "select * from pesanan_item, pesanan where 
		   pesanan_item.id_pesanan = pesanan.id_pesanan and
		   pesanan.id_member = '$id_member' and
		   pesanan.dichekout = 'T'
		   ";
	$q = mysql_query($sql,$kon);
	
	$total_bayar = 0;
	while ($data = mysql_fetch_array($q)) {
		$harga = get_harga_produk($data['id_produk']);
		$total_bayar = $total_bayar + ($harga * $data['qty']);
	}
	
	return $total_bayar;
  }
  
  }
  
  